package org.training.apr.model;

import java.io.Serializable;

public abstract class Model implements Serializable {
	private Long id = null;

	public Model() {
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public boolean equals(Object obj) {
		if(obj == null) {
			return false;
		}
		
		if(this == obj) {
			return true;
		}
		
		if(obj instanceof Model) {
			Model model = (Model) obj;
			if(getId().equals(model.getId()) && this.getClass().equals(obj.getClass())) {
				return true;
			}
		}
		
		return false;
	}

	public int hashCode() {
		if(id == null) {
			return System.identityHashCode(this);
		} 
			
		return this.getClass().hashCode() + id.hashCode();
	}
	
	public String toString() {
		return getClass().getName() + "#" + getId();
	}
}
